package sysu.el.array.ints.algors;
/**
 * 
 * @author edwin
 * @theory New_Arr[i] = Old_Arr[indexes[i]]
 */
public class ArrResortInt {
//	public static void immute(int num, int[] old_arr, int index[]){
//		for (int i=0; i<num; i++){
//			int tmp;
//			tmp = old_arr[i];
//			old_arr[i] = old_arr[index[i]];
//			old_arr[index[i]] = tmp; 
//		}
//	}
	
	public static int[] apply(int num, int[] old_arr, int index[]){
		int[] newArr = new int[num];
		for (int i=0; i<num; i++){
			newArr[i] = old_arr[index[i]];
		}
		return newArr;
	}
	
	
	public static int[] apply(int[] old_arr, int num, int index[]){
		int[] newArr = new int[num];
		for (int i=0; i<num; i++){
			newArr[i] = old_arr[index[i]];
		}
		return newArr;
	}
	
	public static void main(String argv[]){
		int k[] = {1, 2, 3, 4, 5};
		int idx[] = {1, 3, 2, 4, 0};
		k = ArrResortInt.apply(5, k, idx);
//		k = RestoreWithIndexes.mute(5, k, idx);
		for (int i: k){
			System.out.print(i + "\t");
		}
	}
}
